#include <ximera/audio/openal/openal.hpp>
#include <boost/format.hpp>

#if defined(XIMERA_PRAGMA_COMMENT_LIB) && !defined(XIMERA_NO_AUTOLINK)

#pragma comment(lib, "alut.lib")
#pragma comment(lib, "openal32.lib")

#endif

namespace ximera { namespace audio { namespace openal
{
    void checkErrorAndThrow()
    {
        ALenum error = alutGetError();
        if (error != AL_NO_ERROR)
        {
            alGetError();
            XIMERA_THROW(OpenAlException, (boost::wformat(L"Alut error with code: %1%\n"
                L"and message: %2%") % error % alutGetErrorString(error)).str());
        }

        error = alGetError();
        if (error != AL_NO_ERROR)
            XIMERA_THROW(OpenAlException, (boost::wformat(L"OpenAl error with code: %1%") % error).str());        
    }

    void checkErrorAndThrow(String const& message)
    {
        ALenum error = alutGetError();
        if (error != ALUT_ERROR_NO_ERROR)
        {
            alGetError();
            XIMERA_THROW(OpenAlException, (boost::wformat(L"Alut error with code: %1% "
                L"and string: %2% "
                L"and message: %3%") % error % alutGetErrorString(error) % message).str());
        }

        error = alGetError();
        if (error != AL_NO_ERROR)
        {
            XIMERA_THROW(OpenAlException, (boost::wformat(L"OpenAl error with code: %1% "
                L"and message: %2%") % error % message).str());
        }        
    }
}}}